package jp.co.ikd.util;

import static jp.co.ikd.util.Check.isDate;
import static jp.co.ikd.util.Check.isDateYMD;
import static jp.co.ikd.util.Check.isDateYMDFormat;
import static jp.co.ikd.util.Check.isTimeStamp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

public class CheckTest {

	@Test
	public void testIsTimeStamp() {
		assertEquals(true, isTimeStamp("20100101000000000"));
		assertEquals("9999年", true, isTimeStamp("99991101000000000"));
		assertEquals("999秒", true, isTimeStamp("20100101000000999"));

		assertEquals("月が不正", false, isTimeStamp("20101301000000000"));
		assertEquals("日が不正", false, isTimeStamp("20100132000000000"));
		assertEquals("時が不正", false, isTimeStamp("20100101250000000"));
		assertEquals("分が不正", false, isTimeStamp("20100101006100000"));
		assertEquals("秒が不正", false, isTimeStamp("20100101000061999"));
	}

	@Test
	public void testIsDate() {

		assertEquals(false, isDate("20100101", ""));
		assertEquals(true, isDate("20100101", "yyyy"));
		assertEquals(false, isDate("20100101", "HH"));

		try {
			isDate("20100101", "XXX");
			fail();
		} catch (IllegalArgumentException ie) {

		} catch (Exception e) {
			fail();
		}

		try {
			isDate("20100101", null);
			fail();
		} catch (NullPointerException ne) {

		} catch (Exception e) {
			fail();
		}

		assertEquals(false, isDate("", DateUtil.FORMATED_YYYYMMDD));
		assertEquals(false, isDate(null, DateUtil.FORMATED_YYYYMMDD));
		assertEquals(false, isDate(null, ""));
		assertEquals(false, isDate("", ""));
		assertEquals(false, isDate(null, null));

		assertEquals(true, isDateYMD("20100101"));

		assertEquals(false, isDateYMD(""));
		assertEquals(false, isDateYMD(null));

		assertEquals(true, isDateYMDFormat("2010/01/01"));
		// assertEquals(true, isDate("201001", DatePattern.PLANE_YYYYMM));
		// assertEquals(true, isDate("20100101", DatePattern.PLANE_YYYYMMDD));
		// assertEquals(true, isDate("2010/01/01 12:34:56", DatePattern.FORMATED_YYYYMMDDHH24MISS));
		// assertEquals(true, isDate("12:34:56", DatePattern.HH24MISS));
		//
		// assertEquals("ありえない月 2010/13/01", false, isDate("20101301", DatePattern.PLANE_YYYYMMDD));
		// assertEquals("ありえない日ｔ 2010/01/32", false, isDate("20100132", DatePattern.PLANE_YYYYMMDD));

	}

	@Test
	public void testIsGraterThan() throws ParseException {

		DateFormat df = new SimpleDateFormat("yyyy/MM/dd");

		Date target = df.parse("2001/01/01");
		Date compare_new = df.parse("2002/01/01");
		Date compare_old = df.parse("2000/01/01");
		Date compare_equal = df.parse("2001/01/01");

		df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

		Date compare_equal2 = df.parse("2001/01/01 12:34:56");

		assertEquals(false, Check.isGraterThan(target, compare_new));
		assertEquals(true, Check.isGraterThan(target, compare_old));
		assertEquals(false, Check.isGraterThan(target, compare_equal));

		assertEquals(false, Check.isGraterEqual(target, compare_new));
		assertEquals(true, Check.isGraterEqual(target, compare_old));
		assertEquals(true, Check.isGraterEqual(target, compare_equal));

		assertEquals(true, Check.isGraterEqual(target, compare_equal2));

		assertEquals(true, Check.isLessthan(target, compare_new));
		assertEquals(false, Check.isLessthan(target, compare_old));
		assertEquals(false, Check.isLessthan(target, compare_equal));

		assertEquals(true, Check.isLessEqual(target, compare_new));
		assertEquals(false, Check.isLessEqual(target, compare_old));
		assertEquals(true, Check.isLessEqual(target, compare_equal));

	}
}
